package org.ccay.hypertext.service.impl;

import javax.inject.Inject;
import javax.inject.Named;

import org.ccay.core.base.PageVO;
import org.ccay.core.base.PagedResult;
import org.ccay.core.exception.ApplicationException;
import org.ccay.hypertext.StaticResource;
import org.ccay.hypertext.dao.IPlainHyperTextDao;
import org.ccay.hypertext.dao.IStaticResourceDao;
import org.ccay.hypertext.service.IStaticResourceService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;

@Named("staticResourceHyperTextService")
public class StaticResourceHyperTextService implements IStaticResourceService {
	/**
	 * 静态资源缓存名称
	 */
	public static final String STATIC_RESOURCE = "StaticResource";
	
	@Inject
	private IStaticResourceDao staticResourceDao;
	
	@Inject
	private IPlainHyperTextDao plainHyperTextDao;
	
	@Override
	public StaticResource findHyperText(StaticResource hyperText) {
		return staticResourceDao.findHyperText(hyperText);
	}

	@Override
	@CacheEvict(value=STATIC_RESOURCE,allEntries=true)
	public void create(StaticResource hyperText) throws ApplicationException {
		plainHyperTextDao.create(hyperText);
		staticResourceDao.updateUrl(hyperText);
	}

	@Override
	@CacheEvict(value=STATIC_RESOURCE,allEntries=true)
	public void delete(StaticResource hyperText) throws ApplicationException {
		plainHyperTextDao.delete(hyperText);
		
	}

	@Override
	@Cacheable(value=STATIC_RESOURCE)
	public StaticResource findByUrL(String url) {
		return staticResourceDao.findByUrL(url);
	}

	@Override
	public PagedResult<StaticResource> findPagedHypertextList(StaticResource hypertext, PageVO page) {
		return staticResourceDao.findPagedHypertextList(hypertext,page);
	}
}
